<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>新闻动态</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<link href="../../css/news_list/index.css" rel="stylesheet" />
		<script src="../../js/statistics.js"></script>
		<style>
			
			.mui-scroll{
				min-height:100vh;
				background: #fff;
			}

		</style>
	</head>

	<body>
		<div class="mui-content  mui-scroll-wrapper" id="pullrefresh">
			<div class='mui-scroll'>
				<ul class="mui-table-view mui-table-view-chevron video-news" id='load_list'>
					<!--<li>
						<div class="img-box">
							<img src="http://citygo.0519ztnet.com/ueditor/php/upload/image/20171110/1510300192765322.jpg">
							<span></span>
							<div class="shadow"></div>
						</div>
						<div class="title-box">
							<p>我是新闻标题诶日你妈哟瓜麻批</p>
							<span>2017-01-11</span>
							<span>288</span>
						</div>
					</li>-->
				</ul>
			</div>
		</div>
		<div class='kong'>
			<img src="../../images/my/index/null.png" alt="" />
		</div>
		<script src='../../plugins/template/template.js'></script>
		<script src='../../plugins/jquery/jquery-3.1.0.min.js'></script>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src="../../js/fontset.js"></script>
		<script src="../../js/md5.js"></script>
		<script src="../../js/getApiToken.js" type="text/javascript" charset="utf-8"></script>
		<!--<script type="text/javascript" src='../../js/news_list/index.js'></script>-->
		<script id="item" type="text/html">
	    	{{each data as value i}}
				<li data-id="{{value.id}}">
					<div class="img-box">
						<img src="{{baseUrl}}{{value.front_cover}}" />
						<span></span>
						<div class="shadow"></div>
					</div>
					<div class="title-box">
						<p>{{value.title}}</p>
						<span>{{value.time}}</span>
						<span>{{value.views}}</span>
					</div>
				</li>
	    	{{/each}}
		</script>
		<script>
			var li_list,
				lastId,
				shareimg,//微信所需图片
				type1 = '',
				type2 = '';
			mui.init({
				pullRefresh:{
					container:'#pullrefresh',
					down : {
			     	//height:50,//可选,默认50.触发下拉刷新拖动距离,
						auto: false,//可选,默认false.自动下拉刷新一次
						contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
						contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
						contentrefresh : "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
						callback:pulldownRefresh
					},
					up:{
						height:50,
						contentrefresh:'正在加载...',
						contentnomore:'没有更多数据了~',
						callback:pullupRefresh
					}
				}
			});
			//数据列表
			mui.plusReady(function() {
				//选择日历 
				window.addEventListener('chooseDate',function(){
					mui.openWindow({
						url:'dateChoose.html',
						id:'dateChoose.html'
					})
				});
				window.addEventListener('checkDate',function(event){
					var wait = plus.nativeUI.showWaiting();
					if(event.detail.type == 1){
						type1 = event.detail.time;
						type2 = '';
					}else{
						type1 = '';
						type2 = event.detail.time;
					}
					initList();
					mui.later(function(){
						wait.close();
					},888);
					
				});
				initList();
				//页面跳转
				$('#load_list').on('tap', 'li', function(e) {
					var detail_id = $(this).attr('data-id'),
						href = $(this).attr('href');
					
					//获取点击的新闻左侧图片
					shareimg=$(this).find('img').attr('src');
					console.log(shareimg+'微信所需图片');
					
//					console.log($(this).find('img').attr('src').width+'-----图片宽度');
//					console.log($(this).find('img').attr('src').height+'-----图片高度');
					
					
					var theImage = new Image();
					theImage.src = $(this).find('img').attr('src');
					
					// Get accurate measurements from that.
					var imageWidth = theImage.width;
					var imageHeight = theImage.height;
//					console.log(imageWidth+'-------宽度');
//					console.log(imageHeight+"------高度");
					
					
					
					
					var user_id = plus.storage.getItem('cg_user_id'),
						user_token = plus.storage.getItem('cg_user_token');
					mui.openWindow({
						url: 'video_detail.html',
						id:'video_detail.html',
						extras:{
							'detail_id': detail_id
						}
					})
				});
				function initList(){
					$("#load_list").empty();
					myAjax(
						'news/ly_news/getList','get',
						{	'type1': type1,
							'type2': type2,
							'total': 8
						}, function(data) {
							console.log(JSON.stringify(data));
							if(data.success){
								if(!data.data.length){
						 			$('.kong').show();
									mui('#pullrefresh').pullRefresh().disablePullupToRefresh();
						 		}else{
						 			$('.kong').hide();
						 			mui('#pullrefresh').pullRefresh().enablePullupToRefresh();
						 			var length = data.data.length-1;
									lastId=data.data[length].id;
									li_list={
					                    data:data.data,
					                    baseUrl:_baseUrl
					                };
									var li_item = template('item', li_list);
									$("#load_list").append(li_item);
						 		}
							}
						}
					)
				}
				
			});
		//下拉刷新
		function pulldownRefresh(){
			myAjax('news/ly_news/getList','get',
				{	'type1': type1,
					'type2': type2,
					'total':8
				},function(data){
					if(data.success){
						if(!data.data.length){
				 			$('.kong').show();
							mui('#pullrefresh').pullRefresh().disablePullupToRefresh();
				 		}else{
				 			var length = data.data.length-1;
							lastId=data.data[length].id;
							li_list={
			                    data:data.data,
			                    baseUrl:_baseUrl
			                };
							var li_item = template('item', li_list);
							$("#load_list").empty().append(li_item);
				 		}
                        mui.later(function() {
							mui('#pullrefresh').pullRefresh().endPulldownToRefresh();;
							mui('#pullrefresh').pullRefresh().refresh(true);
						}, 1500);		
					}
				}
			)
		}	
		//上拉加载
		function pullupRefresh(){
			myAjax('news/ly_news/getList','get',
				{
					'type1': type1,
					'type2': type2,
					'lastId':lastId,
					'total':6
				},function(data){
					if(data.success){
						console.log(JSON.stringify(data))
						if(data.data.length == 0){
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
							
						}else{
							if(data.data.length < 6){
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
							}else{
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
							}
							loadMore(data.data);
							var length = data.data.length-1;
							lastId = data.data[length].id;
							console.log(lastId)
						}
					}else{
						mui.toast(data.error_msg);
					}
				}
			)
		}
		function loadMore(data){
			li_list={
                data:data,
                baseUrl:_baseUrl
            };
			var li_item = template('item', li_list);
			$("#load_list").append(li_item);
		}
		</script>
	</body>
</html>